<?php
$id_analise = 1;

$conexao = mysql_connect("r2d2.ger.ufsc.br", "panic", "p4n1c");
$con = mysql_select_db("panic", $conexao) or die(mysql_error());

$query = "delete from comparation_cache";
$resp = mysql_query($query, $conexao);

$query = "SELECT id_seq FROM en_seq WHERE id_db in (SELECT id_db_in FROM analysis WHERE id_analysis='$id_analise')";
$resp = mysql_query($query, $conexao);
$seqin_ids = array();
while ( ( $seqin_id = mysql_fetch_array($resp) ) !== false )
{
	$seqin_ids[] = $seqin_id;
}

$query = "SELECT id_seq FROM en_seq WHERE id_db in (SELECT id_db_db FROM analysis WHERE id_analysis='$id_analise')";
$resp = mysql_query($query, $conexao);
$seqdb_ids = array();
while ( ( $seqdb_id = mysql_fetch_array($resp) ) !== false )
{
	$seqdb_ids[] = $seqdb_id;
}

$count_in = count($seqin_ids);
$count_db = count($seqdb_ids);
echo "Count IN - ".$count_in."\n";
echo "Count DB - ".$count_db."\n";

for ($in = 0; $in < $count_in; $in++){
	$query = "INSERT INTO comparation_cache VALUES ";
	for ($db = 0; $db < $count_db; $db++){
		if(!($db == 0)) $query .= ",";
		$query .= "(null,0,{$seqin_ids[$in][0]},{$seqdb_ids[$db][0]})";
	}
	mysql_query($query,$conexao);
}

?>
